package com.letoken.platform.pub.util;

import java.util.List;

public class ListUtil {

    public static int getTotalPages(int totalItems, int itemsPerPage) {
        return (totalItems % itemsPerPage == 0) ? (totalItems / itemsPerPage) : (totalItems / itemsPerPage + 1);
    }

    public static List getCurrentPageData(List data, int currentPage, int itemsPerPage) {
        int startIndex = (currentPage - 1) * itemsPerPage;
        if (startIndex >= data.size()) {
            throw new IndexOutOfBoundsException("超出索引范围！");
        }

        int endIndex = Math.min(startIndex + itemsPerPage, data.size());
        return data.subList(startIndex, endIndex);
    }
}
